﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using T.FAS.Action.MetaData.Entity;
using T.FAS.Base.Dao;
using Teld.Core.DAC.Service;
using Teld.Core.DataAccessEx.Core;

namespace T.FAS.Action.Dev.Dao
{
    public class ActionMetaDataMethodParamELBDao : DaoService<ActionMetaDataMethodParam>
    {
        public override string TableName => "FAS_ActionMetaDataMethodParam";
        public override string IDColumnName => "ID";
        public override List<string> ExceptColumnName
            => DaoUtil.GetExceptionColumn<ActionMetaDataMethodParam>(
                new List<string>
                {
                }
            );
        public ActionMetaDataMethodParamELBDao() : base()
        {
            DBName = "TeldFAS";
        }
        public override Dictionary<string, PropertyInfo> GetColumns()
        {
            return DaoServiceExtension.GetAllColumns<ActionMetaData>(base.GetColumns());
        }
        public override ActionMetaDataMethodParam ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            if (columns.ContainsKey("ParamType"))
                columns.Remove("ParamType");
            if (columns.ContainsKey("ParamSourceType"))
                columns.Remove("ParamSourceType");

            var data = base.ConvertToObject(columns, row);

            data.ParamType = (ParamType)Enum.Parse(typeof(ParamType), Convert.ToString(row["ParamType"]));
            data.ParamSourceType = (ParamSourceType)Enum.Parse(typeof(ParamSourceType), Convert.ToString(row["ParamSourceType"]));

            return data;
        }

        public override Dictionary<string, object> GetDataMapping(ActionMetaDataMethodParam data)
        {
            var mapping = base.GetDataMapping(data);
            mapping.Remove("ParamType");
            mapping.Add("ParamType", (int)data.ParamType);

            mapping.Remove("ParamSourceType");
            mapping.Add("ParamSourceType", (int)data.ParamSourceType);
            return mapping;
        }


        /// <summary>
        /// 根据Action元数据ID删除Action方法参数表数据
        /// </summary>
        /// <param name="actionID"></param>
        public void DeleteActionMetadataMethodParamByActionID(string actionID)
        {
            var parameter = DB.MakeInParam("@ActionMetaDataID", TeldDbDataType.VarChar, actionID);

            DB.ExecSqlStatement(string.Format("delete from {0} where ActionMetaDataID = @ActionMetaDataID", this.TableName), parameter);
        }

        public List<ActionMetaDataMethodParam> GetActionMetaDataMethodParamsByActionID(string actionID)
        {
            var result = base.GetObjectsByFilter($"ActionMetaDataID='{actionID}'");
            var list = new List<ActionMetaDataMethodParam>();
            if (result != null && result.Count > 0)
            {
                result.ForEach(x => list.Add(x as ActionMetaDataMethodParam));
            }
            return list.OrderBy(x=>x.SortOrder).ToList();
        }

        public List<ActionMetaDataMethodParam> GetActionMetaDataMethodParamByFilter(Dictionary<string, string> filter)
        {
            throw new NotImplementedException();
        }

        public ActionMetaDataMethodParam GetActionMetaDataMethodParamByID(string actionParamID)
        {
            throw new NotImplementedException();
        }

        public void AddActionMetaDataMethodParam(ActionMetaDataMethodParam actionParam)
        {
            throw new NotImplementedException();
        }

        public void AddActionMetaDataMethodParamList(ArrayList actionParams)
        {
            throw new NotImplementedException();
        }

        public void UpdateActionMetaDataMethodParam(ActionMetaDataMethodParam actionParam)
        {
            throw new NotImplementedException();
        }

        public void DeleteActionMetaDataMethodParam(string actionParamID)
        {
            throw new NotImplementedException();
        }
    }
}
